package com.example.bgmachine.bgmachine.popupviews;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.example.bgmachine.bgmachine.R;


public class PasswrdSetdialog extends Dialog implements
        View.OnClickListener {
    Context context;

    /**
     * @Fields dialog_cancel : 按钮
     */
    private Button homepage_popup_image_btn_cancel;

    /**
     * @Fields dialog_ok:确定按钮
     */
    private Button homepage_popup_image_btn_ok;

    private Boolean bool;

    private TextView homepage_popup_dialog_menu_textview= null;
  //  private EditText homepage_popup_dialog_tip_textview= null;
    private View.OnClickListener btnOnClick;

    private  PasswordEdit password_passwordedit_center_input_tip = null;

    /**
     * @param @param btnOnClick
     * @return void
     * @throws
     * @Description: 可以自定义button事件
     * @author Sunday
     */
    public void setBtnOnClick(View.OnClickListener btnOnClick) {
        this.btnOnClick = btnOnClick;
        homepage_popup_image_btn_ok.setOnClickListener(btnOnClick);
    }

    public void setBtnOkClick(String text,
                              View.OnClickListener btnOnClick) {
        this.btnOnClick = btnOnClick;
        homepage_popup_image_btn_ok.setText(text);
        homepage_popup_image_btn_ok.setOnClickListener(btnOnClick);

    }

    public PasswrdSetdialog(Context context) {
        super(context, R.style.SundayDialogs);
        this.context = context;
        bool = true;


        Log.d("aaa", "aaa===2");
        //create();
    }
    private void changeDialogStyle() {

        Window window = getWindow();

        if (window != null) {

            WindowManager.LayoutParams attr = window.getAttributes();

            if (attr != null) {

                attr.height = ViewGroup.LayoutParams.WRAP_CONTENT;

                attr.width = ViewGroup.LayoutParams.MATCH_PARENT;

                attr.gravity = Gravity.BOTTOM;

                window.setAttributes(attr);
                window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);


            }

        }

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.passwrd_set_dialog);
        changeDialogStyle();
        init();
        setCancel(bool, "");

        Log.d("aaa", "aaa===1");
    }

    void init() {

        password_passwordedit_center_input_tip = findViewById(R.id.password_passwordedit_center_input_tip);
        homepage_popup_dialog_menu_textview = findViewById(R.id.homepage_popup_dialog_menu_textview);
       // homepage_popup_dialog_tip_textview = findViewById(R.id.homepage_popup_dialog_tip_textview);
        homepage_popup_image_btn_ok = findViewById(R.id.homepage_popup_image_btn_ok);
        homepage_popup_image_btn_cancel = findViewById(R.id.homepage_popup_image_btn_cancel);
    }



    public void setPopupTipInfor(String infors){
       if(password_passwordedit_center_input_tip != null){
           password_passwordedit_center_input_tip.setText("");
        }

    }
    public String getPopupTipInfor(){
        if(password_passwordedit_center_input_tip != null){

            String infors =  password_passwordedit_center_input_tip.getText().toString();
            return infors;
        }else{
            return "";
        }

    }
    /**
     * @return void
     * @throws
     * @Description: 是否显示取消按钮
     * @author Sunday
     */
    public void setCancel(Boolean boole, String message) {

        if (boole) {
            homepage_popup_image_btn_cancel.setVisibility(View.VISIBLE);

            homepage_popup_image_btn_cancel.setOnClickListener(this);

        } else {
            homepage_popup_image_btn_cancel.setVisibility(View.GONE);

        }

        if (null != btnOnClick) {
            homepage_popup_image_btn_ok.setOnClickListener(btnOnClick);
        } else {
            homepage_popup_image_btn_ok.setOnClickListener(this);
        }
        homepage_popup_dialog_menu_textview.setText(message);
    }

    /*
     *
     */
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        if (isShowing()) {
            dismiss();
        }
    }/**/
}
